package com.itheima.hw.test2;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class Test {

    public static void main(String[] args) {
        try (
                FileReader fr = new FileReader("day11_io\\src\\com\\itheima\\hw\\test2\\count.txt");

                BufferedReader br = new BufferedReader(fr);

                ){
            //1.读取文件中的免费的次数
            String numStr = br.readLine();
            int num = Integer.parseInt(numStr);

            //2.判断次数是否小于3，展示不同的提示信息
            if(num <= 3){
                System.out.println("恭喜，您还有"+num+"次免费使用机会");
                //3.更新免费使用的次数
                num ++;

                BufferedWriter bw = new BufferedWriter(new FileWriter("day11_io\\src\\com\\itheima\\hw\\test2\\count.txt"));
                bw.write(num+"");
                bw.close();
            }else{
                System.out.println("您已使用完免费次数，请充值");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
